import QtQuick 2.0
import QtQuick.Controls 2.0
//import QtQuick.Layouts 1.3
import QtQuick.Window 2.10
import QtQuick.VirtualKeyboard 2.3
import QtQuick.Dialogs 1.2
//import an.qt.Station 1.0



Window {
    id: window
    visible: true
    width: 800//1280//800
    height: 800//1280
    minimumWidth: 800
    maximumWidth: 800
    minimumHeight: 800
    maximumHeight: 800

    title: qsTr("MOXHI传感器测试")

//    Station{
//        id:stationdev;
//    }

    InputPanel {
        id: inputPanel
        z: 99
        x: 0
        y: window.height
        width: window.width

        states: State {
            name: "visible"
            when: inputPanel.active
            PropertyChanges {
                target: inputPanel
                y: window.height - inputPanel.height
            }
        }
        transitions: Transition {
            from: ""
            to: "visible"
            reversible: true
            ParallelAnimation {
                NumberAnimation {
                    properties: "y"
                    duration: 250
                    easing.type: Easing.InOutQuad
                }
            }
        }
    }

    ComboBox {
        id:selectPort
        y: 55
        width: 248
        height: 30
        font.pixelSize: 15
        font.family: "Microsoft YaHei"
        focusPolicy: Qt.ClickFocus
        anchors.horizontalCenterOffset: -99
        model: portList.text//serialporthelper.querySerialInfo()// [ "Banana", "Apple", "Coconut" ]//onActivated: {serial.setPortName(currentText)}
        anchors.horizontalCenter: parent.horizontalCenter
        onPressedChanged: {
            serialporthelper.querySerialInfo();
        }
    }

    Text {
        id: element2
        x: 177
        y: 26
        color: "#0c00d5"
        text: qsTr("通讯端口")
        font.family: "Microsoft YaHei"
        font.pixelSize: 20
    }
    Text {
        id: element3
        x: 448
        y: 26
        color: "#0c00d5"
        text: qsTr("协议")
        font.family: "Microsoft YaHei"
        font.pixelSize: 20
    }

    ComboBox {
        id:selectxy
        x: 2
        y: 55
        width: 70
        height: 30
        font.pixelSize: 15
        font.family: "Microsoft YaHei"
        model: ["A", "B", "C", "D"]
        anchors.horizontalCenter: parent.horizontalCenter
        focusPolicy: Qt.ClickFocus
        anchors.horizontalCenterOffset: 83
    }

    TextField {
        id: inputname
        x: 16
        y: 56
        width: 141
        height: 29
        text: station.text
        font.pixelSize: 15
        font.family: "Microsoft YaHei"//qsTr("")
        opacity: 1
        z: 0
        scale: 1
        renderType: Text.QtRendering
        placeholderText: "给设备取个名字"
        wrapMode: Text.NoWrap
    }

    Button {
        id: button
        x: 675
        y: 55
        width: 86
        height: 30
        text: "添加"
        font.pixelSize: 15
        font.family: "Microsoft YaHei"
        display: AbstractButton.TextBesideIcon
        spacing: 5
        //font.capitalization: Font.Capitalize
        onClicked: {
            //            if(selectxy.currentText=="")
            //            {
            //                serialport.serialWrite(send.text)
            //            }
            //            else if(selectxy.currentText=="")
            //            {}
//            console.log(station.text);
//            station.text="hello test";
//            console.log(station.text);

            devicelist.addDevice(inputname.text,selectPort.currentText,selectxy.currentText,selectaddr.currentText);
            console.log(devicelist.rowCount());
        }
    }

    ComboBox {
        id: selectaddr
        x: -1
        y: 55
        width: 82
        height: 30
        font.pixelSize: 15
        font.family: "Microsoft YaHei"
        anchors.horizontalCenterOffset: 191
        anchors.horizontalCenter: parent.horizontalCenter
        model: ["01", "02", "03", "04", "05", "06", "07", "08", "09"]
        focusPolicy: Qt.ClickFocus
    }

    ListView {
        id:lv2
        x: 17
        y: 112
        width: 769
        height: 194

        model: devicelist//.polygons

        delegate: ItemDelegate {

                Rectangle {
                    width: 10
                    height: parent.height/2
                    color: colorCode
                    anchors.verticalCenter: parent.verticalCenter
                }
            Text{
                font.pixelSize: 12
                font.family: "Microsoft YaHei"//qsTr("")
                text: "   "+name+"(端口"+portName+",协议"+protocol+",地址"+commAddr+"):|:"+dataString
                anchors.verticalCenter: parent.verticalCenter
            }


            width: parent.width
            onClicked: {
                console.log("clicked:", index);
                serialporthelper.clickDeviceItem(index);
            }

        }

        ScrollIndicator.vertical: ScrollIndicator { }
    }

    Text {
        id: element4
        x: 550
        y: 26
        color: "#0c00d5"
        text: qsTr("地址")
        font.family: "Microsoft YaHei"
        font.pixelSize: 20
    }

    Text {
        id: element5
        x: 25
        y: 26
        color: "#0c00d5"
        text: qsTr("设备名称")
        styleColor: "#00000000"
        font.family: "Microsoft YaHei"
        font.pixelSize: 20
    }

    ListView {
        id: lv3
        x: 17
        y: 420
        width: 769
        height: 144
        model: hostlist
        ScrollIndicator.vertical: ScrollIndicator {
        }
        delegate: ItemDelegate {
            width: parent.width
            Rectangle {
                width: 10
                height: parent.height/2
                color: colorCode
                anchors.verticalCenter: parent.verticalCenter
            }

            Text {
                text: "   "+name+"(IP"+hostIp+",端口"+hostPort+",协议"+protocol+"):|:"+dataString
                anchors.verticalCenter: parent.verticalCenter
                font.pixelSize: 12
                font.family: "Microsoft YaHei"
            }
            onClicked: {
                console.log("clicked:", index);
                qmlconncpp.clickHostItem(index);
            }
        }
    }

    TextField {
        id: inputIp
        x: 197
        y: 363
        width: 166
        height: 29
        text: "192.168.43.35"
        font.pixelSize: 15
        scale: 1
        z: 0
        placeholderText: "上报平台的IP地址"
        inputMethodHints: Qt.ImhDigitsOnly
        wrapMode: Text.NoWrap
        font.family: "Microsoft YaHei"
        renderType: Text.QtRendering
        opacity: 1
    }

    Text {
        id: element6
        x: 204
        y: 330
        color: "#0c00d5"
        text: qsTr("上报平台地址")
        font.pixelSize: 20
        styleColor: "#00000000"
        font.family: "Microsoft YaHei"
    }

    Text {
        id: element7
        x: 502
        y: 332
        color: "#0c00d5"
        text: qsTr("数据协议")
        font.pixelSize: 20
        font.family: "Microsoft YaHei"
    }

    ComboBox {
        id: selectnetxy
        x: 8
        y: 364
        width: 144
        height: 30
        font.pixelSize: 15
        anchors.horizontalCenterOffset: 174
        anchors.horizontalCenter: parent.horizontalCenter
        focusPolicy: Qt.ClickFocus
        model: ["HJ212-2017"]//,"HJ212-2015"]
        font.family: "Microsoft YaHei"
    }

    Button {
        id: button1
        x: 675
        y: 364
        width: 86
        height: 30
        text: "添加"
        font.pixelSize: 15
        display: AbstractButton.TextBesideIcon
        spacing: 5
        font.family: "Microsoft YaHei"
        onClicked: {
            hostlist.addHost(ptname.text,inputIp.text,inputPort.text,selectnetxy.currentText);
            console.log(hostlist.rowCount());
        }
    }

    TextField {
        id: inputPort
        x: 384
        y: 364
        width: 102
        height: 29
        text: "8234"
        font.pixelSize: 15
        scale: 1
        z: 0
        placeholderText: "平台端口"
        inputMethodHints: Qt.ImhDigitsOnly
        wrapMode: Text.NoWrap
        font.family: "Microsoft YaHei"
        renderType: Text.QtRendering
        opacity: 1
    }

    Text {
        id: element8
        x: 393
        y: 332
        color: "#0c00d5"
        text: qsTr("端口")
        font.pixelSize: 20
        styleColor: "#00000000"
        font.family: "Microsoft YaHei"
    }

    TextField {
        id: ptname
        x: 25
        y: 363
        width: 141
        height: 29
        text: station.text
        font.pixelSize: 15
        renderType: Text.QtRendering
        scale: 1
        font.family: "Microsoft YaHei"
        wrapMode: Text.NoWrap
        placeholderText: "给平台取个名字"
        z: 0
        opacity: 1
    }

    Text {
        id: element9
        x: 34
        y: 330
        color: "#0c00d5"
        text: qsTr("平台名称")
        font.pixelSize: 20
        font.family: "Microsoft YaHei"
        styleColor: "#00000000"
    }

    TextField {
        id: inputIp1
        x: 47
        y: 590
        width: 165
        height: 25
        text: station.MN//"010000A8900016F000169DC0"
        enabled: false
        font.pixelSize: 10
        renderType: Text.QtRendering
        scale: 1
        font.family: "Microsoft YaHei"
        wrapMode: Text.NoWrap
        placeholderText: "MN"
        inputMethodHints: Qt.ImhDigitsOnly
        z: 0
        opacity: 1
    }

    Text {
        id: element10
        x: 14
        y: 593
        color: "#0c00d5"
        text: qsTr("编号")
        font.pixelSize: 15
        font.family: "Microsoft YaHei"
        styleColor: "#00000000"
    }

    TextField {
        id: inputPort1
        x: 263
        y: 590
        width: 55
        height: 25
        text: station.PW//"123456"
        enabled: false
        font.pixelSize: 10
        renderType: Text.QtRendering
        scale: 1
        font.family: "Microsoft YaHei"
        wrapMode: Text.NoWrap
        placeholderText: "PW"
        inputMethodHints: Qt.ImhDigitsOnly
        z: 0
        opacity: 1
    }

    Text {
        id: element11
        x: 229
        y: 593
        color: "#0c00d5"
        text: qsTr("密码")
        font.pixelSize: 15
        font.family: "Microsoft YaHei"
        styleColor: "#00000000"
    }

    TextField {
        id: inputPort2
        x: 570
        y: 589
        width: 105
        height: 25
        text: station.SystemTime//"123456"
        inputMethodHints: Qt.ImhDigitsOnly
        font.pixelSize: 10
        font.family: "Microsoft YaHei"
        z: 0
        wrapMode: Text.NoWrap
        enabled: false
        placeholderText: "平台端口"
        scale: 1
        opacity: 1
        renderType: Text.QtRendering
    }

    Text {
        id: element12
        x: 537
        y: 592
        color: "#0c00d5"
        text: qsTr("时间")
        font.pixelSize: 15
        font.family: "Microsoft YaHei"
        styleColor: "#00000000"
    }

    TextField {
        id: inputPort3
        x: 371
        y: 590
        width: 37
        height: 25
        text: station.OverTime//"99"
        inputMethodHints: Qt.ImhDigitsOnly
        font.family: "Microsoft YaHei"
        font.pixelSize: 10
        z: 0
        wrapMode: Text.NoWrap
        enabled: false
        placeholderText: "OverTime"
        scale: 1
        opacity: 1
        renderType: Text.QtRendering
    }

    Text {
        id: element13
        x: 337
        y: 593
        color: "#0c00d5"
        text: qsTr("超时")
        styleColor: "#00000000"
        font.family: "Microsoft YaHei"
        font.pixelSize: 15
    }

    TextField {
        id: inputPort4
        x: 462
        y: 590
        width: 37
        height: 25
        text: station.ReCount//"3"
        inputMethodHints: Qt.ImhDigitsOnly
        font.pixelSize: 10
        font.family: "Microsoft YaHei"
        z: 0
        wrapMode: Text.NoWrap
        enabled: false
        placeholderText: "ReCount"
        scale: 1
        opacity: 1
        renderType: Text.QtRendering
    }

    Text {
        id: element14
        x: 428
        y: 592
        color: "#0c00d5"
        text: qsTr("重发")
        font.pixelSize: 15
        font.family: "Microsoft YaHei"
        styleColor: "#00000000"
    }

    TextField {
        id: inputPort5
        x: 107
        y: 633
        width: 68
        height: 25
        text: station.RtdInterval//"3600"
        inputMethodHints: Qt.ImhDigitsOnly
        font.family: "Microsoft YaHei"
        font.pixelSize: 10
        z: 0
        wrapMode: Text.NoWrap
        enabled: false
        placeholderText: "RtdInterval"
        scale: 1
        opacity: 1
        renderType: Text.QtRendering
    }

    Text {
        id: element15
        x: 177
        y: 635
        color: "#0c00d5"
        text: qsTr("秒")
        styleColor: "#00000000"
        font.family: "Microsoft YaHei"
        font.pixelSize: 15
    }

    TextField {
        id: inputPort6
        x: 309
        y: 633
        width: 41
        height: 25
        text: station.MinInterval//"30"
        inputMethodHints: Qt.ImhDigitsOnly
        font.family: "Microsoft YaHei"
        font.pixelSize: 10
        z: 0
        wrapMode: Text.NoWrap
        enabled: false
        placeholderText: "MinInterval"
        scale: 1
        opacity: 1
        renderType: Text.QtRendering
    }

    Text {
        id: element16
        x: 217
        y: 635
        color: "#0c00d5"
        text: qsTr("分钟上报间隔")
        styleColor: "#00000000"
        font.family: "Microsoft YaHei"
        font.pixelSize: 15
    }

    Text {
        id: element17
        x: 398
        y: 635
        color: "#0c00d5"
        text: qsTr("设备状态上报")
        font.pixelSize: 15
        font.family: "Microsoft YaHei"
        styleColor: "#00000000"
    }

    TextField {
        id: inputPort7
        x: 492
        y: 632
        width: 50
        height: 25
        text: station.DeviceStateView
        inputMethodHints: Qt.ImhDigitsOnly
        font.family: "Microsoft YaHei"
        font.pixelSize: 10
        z: 0
        wrapMode: Text.NoWrap
        enabled: false
        placeholderText: "DeviceStateView"
        scale: 1
        opacity: 1
        renderType: Text.QtRendering
    }

    TextField {
        id: inputPort8
        x: 664
        y: 632
        width: 55
        height: 25
        text: station.RealtimeReport
        inputMethodHints: Qt.ImhDigitsOnly
        font.pixelSize: 10
        font.family: "Microsoft YaHei"
        z: 0
        wrapMode: Text.NoWrap
        enabled: false
        placeholderText: "RealtimeReport"
        scale: 1
        opacity: 1
        renderType: Text.QtRendering
    }

    Text {
        id: element18
        x: 570
        y: 635
        color: "#0c00d5"
        text: qsTr("实时数据上报")
        font.family: "Microsoft YaHei"
        font.pixelSize: 15
        styleColor: "#00000000"
    }

    Button {
        id: button2011
        x: 14
        y: 707
        width: 90
        height: 25
        text: "上传实时数据"
        font.family: "Microsoft YaHei"
        spacing: 5
        font.pixelSize: 10
        display: AbstractButton.TextBesideIcon
        onClicked: {
            stationdev.qmlHostSendAuto(2011);
        }
    }

    Button {
        id: button1013
        x: 14
        y: 670
        width: 90
        height: 25
        text: "现场机时间校准"
        font.family: "Microsoft YaHei"
        spacing: 5
        font.pixelSize: 10
        display: AbstractButton.TextBesideIcon
        onClicked: {
            stationdev.qmlHostSendAuto(1013);
        }
    }

    Button {
        id: button2051
        x: 114
        y: 707
        width: 90
        height: 25
        text: "上传分钟数据"
        font.family: "Microsoft YaHei"
        spacing: 5
        font.pixelSize: 10
        display: AbstractButton.TextBesideIcon
        onClicked: {
            stationdev.qmlHostSendAuto(2051);
        }
    }

    Button {
        id: button2061
        x: 215
        y: 707
        width: 90
        height: 25
        text: "上传小时数据"
        font.family: "Microsoft YaHei"
        spacing: 5
        font.pixelSize: 10
        display: AbstractButton.TextBesideIcon
        onClicked: {
            stationdev.qmlHostSendAuto(2061);
        }
    }

    Button {
        id: button2031
        x: 317
        y: 707
        width: 90
        height: 25
        text: "上传日历史数据"
        font.family: "Microsoft YaHei"
        spacing: 5
        font.pixelSize: 10
        display: AbstractButton.TextBesideIcon
        onClicked: {
            stationdev.qmlHostSendAuto(2031);
        }
    }

    Button {
        id: button2021
        x: 114
        y: 670
        width: 90
        height: 25
        text: "设备运行状态"
        font.family: "Microsoft YaHei"
        spacing: 5
        font.pixelSize: 10
        display: AbstractButton.TextBesideIcon
        onClicked: {
            stationdev.qmlHostSendAuto(2021);
        }
    }

    Text {
        id: element19
        x: 352
        y: 635
        color: "#0c00d5"
        text: qsTr("分")
        font.family: "Microsoft YaHei"
        font.pixelSize: 15
        styleColor: "#00000000"
    }

    Text {
        id: element20
        x: 15
        y: 635
        color: "#0c00d5"
        text: qsTr("实时上报间隔")
        font.family: "Microsoft YaHei"
        font.pixelSize: 15
        styleColor: "#00000000"
    }

    Button {
        id: button2041
        x: 215
        y: 670
        width: 90
        height: 25
        text: "设备日历史数据"
        font.family: "Microsoft YaHei"
        font.pixelSize: 10
        display: AbstractButton.TextBesideIcon
        spacing: 5
        onClicked: {
            stationdev.qmlHostSendAuto(2041);
        }
    }

    Button {
        id: button2081
        x: 317
        y: 670
        width: 90
        height: 25
        text: "数采仪开机时间"
        font.family: "Microsoft YaHei"
        font.pixelSize: 10
        display: AbstractButton.TextBesideIcon
        spacing: 5
        onClicked: {
            stationdev.qmlHostSendAuto(2081);
        }
    }

    Button {
        id: button3019
        x: 418
        y: 670
        width: 90
        height: 25
        text: "设备唯一标识"
        font.family: "Microsoft YaHei"
        font.pixelSize: 10
        display: AbstractButton.TextBesideIcon
        spacing: 5
        onClicked: {
            stationdev.qmlHostSendAuto(3019);
        }
    }

    Button {
        id: button3020
        x: 519
        y: 670
        width: 90
        height: 25
        text: "现场机信息"
        font.family: "Microsoft YaHei"
        font.pixelSize: 10
        display: AbstractButton.TextBesideIcon
        spacing: 5
        onClicked: {
            stationdev.qmlHostSendAuto(3020);
        }
    }

    Button {
        id: button2
        x: 693
        y: 754
        text: qsTr("Next Page")
        onClicked: {

        }
    }


//     GridLayout{

//         id:grid

//         anchors.verticalCenter: parent.verticalCenter;

//         anchors.left: parent.left;

//         anchors.leftMargin: 10;



//         rows:6;

//         rowSpacing: 5;

//         columns: 2;

//         columnSpacing: 5



//         Label{

//             text:qsTr("串口")

//         }

//         ComboBox{

//             id:port;

//             model: ["COM1","COM2","COM3"];

//         }



//         Label{

//             text:qsTr("波特率")

//         }

//         ComboBox{

//             id:baudrate;

//             model: ["4800","9600","115200"];

//         }



//         Label{

//             text:qsTr("数据位")

//         }

//         ComboBox{

//             id:databits

//             model: ["6","7","8"];

//         }



//         Label{

//             text:qsTr("校验位")

//         }

//         ComboBox{

//             id:parity

//             model: ["0","2","3"];

//         }



//         Label{

//             text:qsTr("停止位")

//         }

//         ComboBox{

//             id:stopbits

//             model: ["1","2","3"];

//         }



//         Button{

//             text: qsTr("打开串口")

//             highlighted: true

//             Layout.columnSpan: 2;

//             onClicked: {

//                 serialport.serialConnect(port.currentText,baudrate.currentText,

//                    databits.currentText,parity.currentText,stopbits.currentText);

//             }

//         }

//     }



//      ColumnLayout{

//          anchors.left: grid.right

//          anchors.leftMargin: 60;

//          anchors.verticalCenter: parent.verticalCenter

//          spacing: 5

//          TextArea{

//              id:receive;

//              Layout.preferredWidth: 200;

//              Layout.preferredHeight: 200;

//              text: qsTr("Receive:")

//              readOnly: true;

//              background: Rectangle{

//                  color: "gray"

//              }

//          }

//          Button{

//              text: qsTr("接收数据")

//              highlighted: true;

//              onClicked: {

//                  receive.append(serialport.serialRead());

//              }

//          }



//          TextField{

//              id:send;

//              Layout.preferredWidth: 200

//          }



//          Button{

//              text:qsTr("发送数据")

//              highlighted: true

//              onClicked: {

//                  serialport.serialWrite(send.text)

//              }

//          }

//      }

//    MessageDialog {
//        id: messageDialog
//        title: "找到软件的不同版本!"
//        //icon: StandardIcon.Question
//        text: "本地版本:"+station.SoftCurrVer+"\r\n\r\n线上版本:"+station.SoftOnlineVer+"\r\n\r\n是否要切换为线上版本?";
//        standardButtons: StandardButton.Yes | StandardButton.No

//        onYes: serialporthelper.goUpDate();
//        onNo: station.NeedUpdate=false;
////        onAccepted: {
//////            console.log("And of course you could only agree.")
//////            Qt.quit()
////        }
//        visible: station.NeedUpdate;
//    }


}
